Add store function.
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Wed, 14 Sep 2005 19:22:31 +0000 (19:22 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Wed, 14 Sep 2005 19:22:31 +0000 (19:22 +0000)
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
tools/python/xen/xend/xenstore/xstransact.py

index 08e3d9626accf4ba10ce6ae8e1a609173f91d1a4..378dd179cb392e3ffb1beee2eaa22e321cf5f43b 100644 (file)
@@ -121,6 +121,20 @@ class xstransact:
             return ret[0]
         return ret
 
+    def store(self, *args):
+        for tup in args:
+            if len(tup) == 2:
+                (key, val) = tup
+                try:
+                    fmt = { str : "%s",
+                            int : "%i",
+                            float : "%f" }[type(val)]
+                except KeyError:
+                    raise TypeError
+            else:
+                (key, val, fmt) = tup
+            self.write(key, fmt % val)
+
 
     def Read(cls, path, *args):
         while True:
@@ -216,3 +230,22 @@ class xstransact:
                 raise
 
     Gather = classmethod(Gather)
+
+    def Store(cls, path, *args):
+        while True:
+            try:
+                t = cls(path)
+                v = t.store(*args)
+                t.commit()
+                return v
+            except RuntimeError, ex:
+                t.abort()
+                if ex.args[0] == errno.ETIMEDOUT:
+                    pass
+                else:
+                    raise
+            except:
+                t.abort()
+                raise
+
+    Store = classmethod(Store)